<?php

namespace App\Services\Gallery\Model;

use App\Models\Administrator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

class SpaceScheme extends Model
{
    public const SHOW_YES = 1;
    public const SHOW_NO = -1;

    protected $table = 'space_scheme'; 

    protected $fillable = [
        'title','thumb', 'sort', 'is_show','style_id','series_id','acreage','is_recommend'
    ];

    protected $appends = ['creator'];

    public function getCreatorAttribute()
    {
        return $this->user->name;
    }

    public function user()
    {
        return $this->belongsTo(Administrator::class, 'user_id');
    }

    public function category()
    {
        return $this->hasMany(SpaceSchemeContentCategory::class, 'space_scheme_id');
    }

    /**
     * 作用域：显示.
     *
     * @param $query
     *
     * @return mixed
     */
    public function scopeShow($query)
    {
        return $query->where('is_show', self::SHOW_YES);
    }

    /**
     * 作用域：不显示.
     *
     * @param $query
     *
     * @return mixed
     */
    public function scopeNotShow($query)
    {
        return $query->where('is_show', self::SHOW_NO);
    }
}
